<!-- <style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style> -->
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit,Vue.prototype.$vFN.Utils],
  components: {},
  data() {
    return {
      appWindow: window,
      form: {
        mobile: "",
        // 真实姓名
        real_name: "",
        role_id: "",
        role_name: "",

        // 用户名
        username: "",
        // 密码
        // password: "plm@123.Tt",
        password: "",
        // 启用状态
        status: 0,
      },
      // 页面接口地址
      apiUrl: {
        create: "store/admin/add",
        update: "store/admin/edit",
        detail: "store/admin/detail",
      },
      listCanAuthRole: [],
    };
  },
  methods: {
    selectRole(id) {
      this.form.role_id = id;
    },
    // form 提交添加/修改 的参数扩展方法
    mixinEdit_editFormSubmitExtend(data_) {

      if(this.mixinEdit_editType == "update" && this.verification(data_)){
        return false;
      }
     
      return data_;
    },
    // 
    mixinEdit_editDataExtend(data_) {

      if (this.mixinEdit_editType == "add") {
      }
      if (this.mixinEdit_editType == "update") {

        data_.role_name = data_.roles[0].name;
        data_.role_id = data_.roles[0].id;
        // 没有password参数返回，需要修改null值
        data_.password = this.$vFN.Utils.isEmpty(data_.password) == true ? '' : data_.password;
        // 手机号
        data_.mobile = this.$vFN.Utils.isEmpty(data_.mobile) == true ? '' : data_.mobile;
       // 用户名
        data_.username = this.$vFN.Utils.isEmpty(data_.username) == true ? '' : data_.username;
       //真实姓名
        data_.real_name = this.$vFN.Utils.isEmpty(data_.real_name) == true ? '' : data_.real_name;
      }

      return data_;
    },
    // 初始化
    async init() {

      await this.mixinEdit_editBoxInit({
        model: "form",
        id: this.id,
        onInit: async () => {
          // 获取用户信息
          let _data = await this.$vFN.Http.post(
            {
              url: "store/role/index?pageNum=1&pageSize=20",
            },
            window
          );
          if (_data._ok) {
            this.listCanAuthRole = _data.data.list;
            // console.log("7788", this.listCanAuthRole);
          }
          return true;
        },
      });

    },

    // 修改时验证提交填信息
    verification(data_){
      
      //密码验证
     if(!this.$vFN.Utils.isEmpty(data_.password) && !this.$vFN.Utils.isPassword(data_.mobile)){
         this.$vFN.Tools.messageError("密码由8-20位大小写字母和数字的组成");
         return true;
      }

      return false;
    },

  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>
